// 121.买卖股票的最佳时机
package Leetcode_Second_Brush;

public class Solution121 {
    public int maxProfit(int[] prices) {
        int maxProfit = 0;
        int buyIn = prices[0];
        for (int i = 1; i < prices.length; i++) {
            maxProfit = Math.max(maxProfit, prices[i] - buyIn);
            buyIn = Math.min(buyIn, prices[i]);
        }
        return maxProfit;
    } 
}
